package com.cch.examSystem.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSON;
import com.cch.examSystem.entity.Manager;

public class ManagerListServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		Date now = new Date();
		SimpleDateFormat datetime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat time = new SimpleDateFormat("HH:mm:ss");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();

		List manager = new ArrayList();
		Manager m;
		String name = "管理员";
		String account = "admin";
		for (int i = 0; i < 10; i++) {
			m = new Manager(name + i, account + i, "123456",
					"441522199999990000", "10000000000", datetime.format(now),
					1, "192.0.0.1", datetime.format(now));
			m.setId(i);
			manager.add(m);
		}
		for (int i = 10; i < 20; i++) {
			m = new Manager(name + i, account + i, "123456",
					"44152219999999000", "1000000000", datetime.format(now),
					2, "192.0.0.1", datetime.format(now));
			m.setId(i);
			manager.add(m);
		}
		for (int i = 20; i < 200; i++) {
			m = new Manager(name + i, account + i, "123456",
					"44152219999999000", "1000000000", datetime.format(now),
					3, "192.0.0.1", datetime.format(now));
			m.setId(i);
			manager.add(m);
		}
		/*System.out.println(JSON.toJSONString(manager));*/
		request.setAttribute("managerList", manager);
		request.getRequestDispatcher("./manager/managerList.jsp").forward(
				request, response);
		out.flush();
		out.close();
	}
}
